package han.chensing.latos.common.level.content.timeLine;

import han.chensing.latos.common.level.content.timeLine.events.TimeLineMotionEvent;
import han.chensing.latos.common.level.content.timeLine.frame.FrameGeneral;
import han.chensing.latos.common.level.content.timeLine.frame.GeneralEventTypes;
import han.chensing.latos.common.level.util.FrameUtil;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class TimeLineRow implements Serializable {
    
    @Serial private static final long serialVersionUID = -1319857620079728584L;
    protected String name;
    protected boolean hasChanged;
    protected List<TimeLineEventSet<?,?>> timeLineEventSets;

    public TimeLineRow(String name){
        this.name=name;
        this.timeLineEventSets =new ArrayList<>();
        this.hasChanged=true;
    }

    public void makeKeyFrame(float time, GeneralEventTypes type){
        TimeLineEventSet<?,?> timeLineEventSet = FrameUtil.getTimeLineEventSetByType(this, type);
        if (timeLineEventSet==null) return;
        timeLineEventSet.makeLineMoveGeneralKeyFrame(time);
    }

    public void deleteNearestKeyFrame(float time, GeneralEventTypes type){
        TimeLineEventSet<?,?> timeLineEventSet = FrameUtil.getTimeLineEventSetByType(this, type);
        if (timeLineEventSet==null) return;
        timeLineEventSet.deleteNearestKeyFrame(time);
    }

    public void makeLineMoveEvent(float time, GeneralEventTypes type){
        TimeLineEventSet<?,?> timeLineEventSet = FrameUtil.getTimeLineEventSetByType(this, type);
        if (timeLineEventSet==null) return;
        timeLineEventSet.makeLineMoveGeneralEvent(time);
    }

    public void deleteLineMoveEvent(float time, GeneralEventTypes type){
        TimeLineEventSet<?,?> timeLineEventSet = FrameUtil.getTimeLineEventSetByType(this, type);
        if (timeLineEventSet==null)return;
        timeLineEventSet.deleteLineMoveEvent(time);
    }

    public int getAmountOfEventSets(){
        return timeLineEventSets.size();
    }

    public List<TimeLineEventSet<?,?>> getTimeLineEventSets() {
        return timeLineEventSets;
    }

    public void setTimeLineEventSets(List<TimeLineEventSet<?,?>> timeLineEventSets) {
        this.timeLineEventSets = timeLineEventSets;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isHasChanged() {
        return hasChanged;
    }

    public void setHasChanged(boolean hasChanged) {
        this.hasChanged = hasChanged;
    }

    public void initializeWithDefaultObjects(){
        timeLineEventSets.add(new TimeLineEventSet<TimeLineMotionEvent,FrameGeneral>(GeneralEventTypes.X));
        timeLineEventSets.add(new TimeLineEventSet<TimeLineMotionEvent,FrameGeneral>(GeneralEventTypes.Y));
        timeLineEventSets.add(new TimeLineEventSet<TimeLineMotionEvent,FrameGeneral>(GeneralEventTypes.Alpha));
        timeLineEventSets.add(new TimeLineEventSet<TimeLineMotionEvent,FrameGeneral>(GeneralEventTypes.Rotate));
        timeLineEventSets.add(new TimeLineEventSet<TimeLineMotionEvent,FrameGeneral>(GeneralEventTypes.Speed));
    }
}
